package com.lry.basic.redis.readWriteLock;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import redis.clients.jedis.Jedis;

import java.lang.reflect.Method;

public class JedisCglibProxyIntercepter implements MethodInterceptor {
    /**
     *
     * @param proxy 代理对象
     * @param method 目标方法
     * @param objects 目标方法参数
     * @param methodProxy 代理方法
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object proxy, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        //methodProxy.invokeSuper(o,objects);
        //try后会自动调用jedis的close方法释放资源
        try(Jedis jedis = JedisConnectPoll.getJedis()){
            return method.invoke(jedis, objects);
        }

    }
}
